using System;
using System.Linq;
using JNPF.Utils;
using System.Threading.Tasks;
using JNPF.Data;
using JNPF.Data.Util;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using JNPF.Basics.Models;

namespace JNPF.Basics.Logic
{
    public class jiushiCustomeractualcontrollerrealService: DataFactory, jiushiCustomeractualcontrollerrealIService
    {
		/// <summary>
		/// 获取信息
		/// </summary>
		/// <param name="id">主键id</param>
		/// <returns></returns>
		public async Task<jiushiCustomeractualcontrollerrealEntity> GetInfo(int id)
		{
			using (var db = this.Basic)
			{
				return await db.GetEntityAsync<jiushiCustomeractualcontrollerrealEntity>(m => m.Id == id);
			}
		}

		/// <summary>
		/// 列表（分页）
		/// </summary>
		/// <param name="input">请求参数</param>
		/// <returns></returns>
		public async Task<PageResult<jiushiCustomeractualcontrollerrealEntity>> GetPageList(jiushiCustomeractualcontrollerrealListQueryInput input)
		{
			using (var db = this.Basic)
			{
				var queryWhere = ExtLinq.True<jiushiCustomeractualcontrollerrealEntity>();
				var queryParam = input.queryJson.ToObject();
				//查询业务ID
				if (!string.IsNullOrEmpty(input.businessId))
				{
					queryWhere = queryWhere.And(m => m.BusinessId.Contains(input.businessId));
				}
				//查询客户主键
				if (input.customerId.ToInt()!=0)
				{
					queryWhere = queryWhere.And(m => m.CustomerId == input.customerId);
				}
				//查询产权人
				if (!string.IsNullOrEmpty(input.propertyOwner))
				{
					queryWhere = queryWhere.And(m => m.PropertyOwner.Contains(input.propertyOwner));
				}
				//查询房屋类型
				if (!string.IsNullOrEmpty(input.houseType))
				{
					queryWhere = queryWhere.And(m => m.HouseType.Contains(input.houseType));
				}
				//查询坐落
				if (!string.IsNullOrEmpty(input.beLocated))
				{
					queryWhere = queryWhere.And(m => m.BeLocated.Contains(input.beLocated));
				}
				//查询面积
				if (!string.IsNullOrEmpty(input.area))
				{
					queryWhere = queryWhere.And(m => m.Area.Contains(input.area));
				}
				return await db.GetIQueryable<jiushiCustomeractualcontrollerrealEntity>().Where(queryWhere).GetPageResultAsync(input);
			}
		}

		/// <summary>
		/// 创建信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Create(jiushiCustomeractualcontrollerrealEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.InsertAsync(entity);
			}
		}

		/// <summary>
		/// 更新信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Update(jiushiCustomeractualcontrollerrealEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.UpdateAsync(entity);
			}
		}

		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Delete(jiushiCustomeractualcontrollerrealEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.DeleteAsync(entity);
			}
		}

		/// <summary>
		/// 列表
		/// </summary>
		/// <param name="input">请求参数</param>
		/// <returns></returns>
		public async Task<List<jiushiCustomeractualcontrollerrealEntity>> GetList(jiushiCustomeractualcontrollerrealListQueryInput input)
		{
			using (var db = this.Basic)
			{
				var queryWhere = ExtLinq.True<jiushiCustomeractualcontrollerrealEntity>();
				//查询业务ID
				if (!string.IsNullOrEmpty(input.businessId))
				{
					queryWhere = queryWhere.And(m => m.BusinessId.Contains(input.businessId));
				}
				//查询客户主键
				if (input.customerId.ToInt()!=0)
				{
					queryWhere = queryWhere.And(m => m.CustomerId == input.customerId);
				}
				//查询产权人
				if (!string.IsNullOrEmpty(input.propertyOwner))
				{
					queryWhere = queryWhere.And(m => m.PropertyOwner.Contains(input.propertyOwner));
				}
				//查询房屋类型
				if (!string.IsNullOrEmpty(input.houseType))
				{
					queryWhere = queryWhere.And(m => m.HouseType.Contains(input.houseType));
				}
				//查询坐落
				if (!string.IsNullOrEmpty(input.beLocated))
				{
					queryWhere = queryWhere.And(m => m.BeLocated.Contains(input.beLocated));
				}
				//查询面积
				if (!string.IsNullOrEmpty(input.area))
				{
					queryWhere = queryWhere.And(m => m.Area.Contains(input.area));
				}
				return await db.GetIQueryable<jiushiCustomeractualcontrollerrealEntity>().Where(queryWhere).ToListAsync();
			}
		}


    }
}